<template>
  <div class="search">
    <f-drawer ref="drawer" :title="drawerTitle" width="70%" @submit="handleSubmit" @visibleChange="visibleChange">
      <refund-form ref="form1" v-if="drawerVisible&&current=='form1'" @closeDrawer="closeDrawer"></refund-form>
      <refund-details ref="form2" v-if="drawerVisible&&current=='form2'"></refund-details>
    </f-drawer>
  </div>
</template>
<script>
  import RefundDetails from './refund_details'
  import RefundForm from './refund_form'

  export default {
    name: 'RefundDrawer',
    props: {},
    data() {
      return {
        refs: this.$refs,
        drawerVisible: false,
        isEdit: false,
        title: '',
        current: 'form1',
        params: {},
        forms: [
          'form1'
        ]
      }
    },
    methods: {
      showDrawer(data, formName) {
        this.params = data
        this.refs['drawer'].show()
        this.tabClick(formName)
      },
      handleSubmit(callback) {
        this.refs[this.current].handleSubmit(callback)
      },
      visibleChange(drawerVisible) {
        this.drawerVisible = drawerVisible
      },
      closeDrawer() {
        this.$emit('success')
        this.$refs.drawer.close()
      },
      tabClick(name) {
        this.current = name
        if (this.current === 'form1') {
          this.title = '返款申请'
        }
        if (this.current === 'form2') {
          this.title = '查看返款明细'
        }
        this.$nextTick(() => {
          this.refs[this.current].setData(this.params)
        })
      }
    },
    computed: {
      drawerTitle: function() {
        return this.title
      }
    },
    created() {

    },
    components: { RefundForm, RefundDetails }
  }
</script>

<style scoped lang="less" rel="stylesheet/less">

</style>
